/*
 * This file is part of ksPlatform
 * 
 * Copyright (c) 2014-2015
 * 
 * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) 
 * 
 * If you are unsure which license is appropriate for your use, please contact the sales department
 * at 97041437@qq.com.
 */
package cn.com.ksplatform.modules.autocode.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.velocity.tools.ToolManager;

/**
 * ClassName:ToolUtil.java <br/>
 * Date: 2015年12月31日 <br/>
 * 
 * @author Mr.Xiao
 * @version 1.0
 */
public class ToolUtil {
	static Map<String, Object> tools = new HashMap<String, Object>();
	
	public static boolean loaded = false;
	
	public static Map<String, Object> gettools(){
		if(!loaded){
			ToolManager manager = new ToolManager(true);
			manager.configure("../toolbox.xml");
			Map cm = manager.createContext().getToolClassMap();
			for(Object key : cm.keySet()){
				try {
					tools.put(key.toString(), ((Class)(cm.get(key))).newInstance());
				} catch (InstantiationException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			loaded = true;
		}
		return tools;
	}
}
